<?php

class StoreconfigController extends Controller
{
    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    //public $layout='//layouts/column2';

    /**
     * @return array action filters
     */
    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
            'postOnly + delete', // we only allow deletion via POST request
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
        return $this->getRules();
    }

    public function actionIndex(){

        $pagevals = array(
            'page_title' => "Quản trị site",
            'subpage_title' => 'Cài đặt thông tin site',

        );

        $data = StoreConfigModel::model()->findByPk(1);
        if(isset($_POST['store_name'])){
            $data->attributes = array(
                //'id' => 'ID',
                'store_name' => $_POST['store_name'],
                'store_intro' =>  $_POST['store_intro'],
                'email'=> $_POST['email'],
                'address' =>  $_POST['address'],
                'phones' =>  $_POST['phones'],
                'hotlines' =>  $_POST['hotlines'],
                'skype' =>  $_POST['skype'],
                'facebook' =>  $_POST['facebook'],
                'yahoo' =>  $_POST['yahoo'],
                'googleplus' =>  $_POST['googleplus'],
                //'paygate' =>  $_POST['paygate'],
                //'bank_info' =>  $_POST['bank_info'],
                //'video_url' =>  $_POST['video_url'],
                //'title' =>  $_POST['title'],
                'googlemap' =>  $_POST['googlemap'],
                'image_map' =>  $_POST['image_map'],
                'twitter' =>  $_POST['twitter'],
                //'ads_image' =>  $_POST['ads_image'],
                //'ads_title' =>  $_POST['ads_title'],
                //'ads_link' =>  $_POST['ads_link'],
                'other_sites' =>  $_POST['other_sites'],
                'profile_link'=> $_POST['profile_link'],
            );

            if($data->save(false)){
                $this->redirect(array('index'));
            }

        }
        $this->display("storeconfig/storeconfig", array('data'=>$data->attributes, 'pagevals'=>$pagevals) );
    }

    public function actionBankinfo(){
        $pagevals = array(
            'page_title' => "Quản trị thông tin tài khoản thanh toán",
            'subpage_title' => 'Cài đặt thông tin tài khoản',

        );

        $data = StoreConfigModel::model()->findByPk(1);
        if(isset($_POST['paygate'])){
            $data->attributes = array(
                //'id' => 'ID',
                //'store_name' => $_POST['store_name'],
                //'store_intro' =>  $_POST['store_intro'],
                //'email'=> $_POST['email'],
                //'address' =>  $_POST['address'],
                //'phones' =>  $_POST['phones'],
                //'hotlines' =>  $_POST['hotlines'],
                //'skype' =>  $_POST['skype'],
                //'facebook' =>  $_POST['facebook'],
                //'yahoo' =>  $_POST['yahoo'],
                //'googleplus' =>  $_POST['googleplus'],
                //'other_sites' =>  $_POST['other_sites'],
                //'profile_link'=> $_POST['profile_link'],
                //'video_url' =>  $_POST['video_url'],
                //'title' =>  $_POST['title'],
                //'googlemap' =>  $_POST['googlemap'],
                //'image_map' =>  $_POST['image_map'],
                //'twitter' =>  $_POST['twitter'],
                'paygate' =>  $_POST['paygate'],
                'bank_info' =>  $_POST['bank_info'],
                //'ads_image' =>  $_POST['ads_image'],
                //'ads_title' =>  $_POST['ads_title'],
                //'ads_link' =>  $_POST['ads_link'],

            );

            if($data->save(false)){
                $this->redirect(array('bankinfo'));
            }

        }
        $this->display("storeconfig/bankinfo", array('data'=>$data->attributes, 'pagevals'=>$pagevals) );
    }

    public function actionPopup(){
        $pagevals = array(
            'page_title' => "Quản trị Popup",
            'subpage_title' => 'Cài đặt thông tin popup',

        );

        $data = StoreConfigModel::model()->findByPk(1);
        if(isset($_POST['ads_title'])){
            $data->attributes = array(
                //'id' => 'ID',
                //'store_name' => $_POST['store_name'],
                //'store_intro' =>  $_POST['store_intro'],
                //'email'=> $_POST['email'],
                //'address' =>  $_POST['address'],
                //'phones' =>  $_POST['phones'],
                //'hotlines' =>  $_POST['hotlines'],
                //'skype' =>  $_POST['skype'],
                //'facebook' =>  $_POST['facebook'],
                //'yahoo' =>  $_POST['yahoo'],
                //'googleplus' =>  $_POST['googleplus'],
                //'other_sites' =>  $_POST['other_sites'],
                //'profile_link'=> $_POST['profile_link'],
                //'video_url' =>  $_POST['video_url'],
                //'title' =>  $_POST['title'],
                //'googlemap' =>  $_POST['googlemap'],
                //'image_map' =>  $_POST['image_map'],
                //'twitter' =>  $_POST['twitter'],
                //'paygate' =>  $_POST['paygate'],
                //'bank_info' =>  $_POST['bank_info'],
                'ads_image' =>  $_POST['ads_image'],
                'ads_title' =>  $_POST['ads_title'],
                'ads_link' =>  $_POST['ads_link'],

            );

            if($data->save(false)){
                $this->redirect(array('popup'));
            }

        }
        $this->display("storeconfig/popup", array('data'=>$data->attributes, 'pagevals'=>$pagevals) );
    }
}
